<script>
  import { computed, nextTick } from '@vue/runtime-core'
  import moment from 'moment'
  import { useRouter, useRoute } from 'vue-router'
  export default function () {
    const renderSex = computed(
      () => (val) => val !== null ? (val === 1 ? '男' : '女') : ''
    )
    const renderTime = computed(() => (val) => {
      return moment(val).format('YYYY-MM-DD HH:mm')
    })
    const renderDay = computed(() => (val) => moment(val).format('YYYY-MM-DD'))
    const renderHour = computed(() => (val) => moment(val).format('HH:mm'))
    const splitStr = computed(() => (val) => {
      if (!val) {
        return []
      } else {
        return val.split(',')
      }
    })
    const router = useRouter()
    const route = useRoute()
    const routerFilter = async function (params) {
      if (params.query) {
        router.push({
          path: router.currentRoute.value.path,
          query: params.query,
        })
      } else if (params.delete) {
        const query = {}
        Object.keys(route.query).forEach((key) => {
          if (key !== params.delete) {
            query[key] = route.query[key]
          }
        })
        if (params.emrId) {
          query['emrId'] = params.emrId
        }
        // await nextTick()
        console.log('query = ' + JSON.stringify(query))
        router.push({ path: router.currentRoute.value.path, query: query })
      }
    }
    return {
      renderSex,
      renderTime,
      renderHour,
      renderDay,
      routerFilter,
      splitStr,
    }
  }
</script>
